﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using EHR.Common;

namespace CommunitySystem.PageView
{
    public partial class System_MarkControl : UserControl
    {
        private EmpbasicService.EmpBasicServiceClient Client = new EmpbasicService.EmpBasicServiceClient();
        
        public System_MarkControl()
        {
            InitializeComponent();
            Client.GetSystemMarkCompleted += new EventHandler<EmpbasicService.GetSystemMarkCompletedEventArgs>(Client_GetSystemMarkCompleted);
            Client.GetSystemMarkAsync(Session.LoginUser.LoginName,0,20,"","");
            Client.GetSystemMarkCountsCompleted += new EventHandler<EmpbasicService.GetSystemMarkCountsCompletedEventArgs>(Client_GetSystemMarkCountsCompleted);
            Client.GetSystemMarkCountsAsync(Session.LoginUser.LoginName, "", "");
        }

        void Client_GetSystemMarkCountsCompleted(object sender, EmpbasicService.GetSystemMarkCountsCompletedEventArgs e)
        {
            int count = e.Result;
            ObservableCollection<int> source = new ObservableCollection<int>();
            for (int i = 0; i < count; i++)
            {
                source.Add(i + 1);
            }
            PagedCollectionView pcv = new PagedCollectionView(source);
            dataPager1.PageSize = 1;
            dataPager1.Source = pcv;
        }

        void Client_GetSystemMarkCompleted(object sender, EmpbasicService.GetSystemMarkCompletedEventArgs e)
        {
            DGRole.ItemsSource = e.Result;
        }

        private void dataPager1_PageIndexChanged(object sender, EventArgs e)
        {
            int index = dataPager1.PageIndex;
            Client.GetSystemMarkAsync(Session.LoginUser.LoginName, index * 20, index * 20 + 20, ChaName.Text, datepicker.SelectedDate.ToString());
        }

        private void ChaData_Click(object sender, RoutedEventArgs e)
        {
            Client.GetSystemMarkAsync(Session.LoginUser.LoginName, 0, 20, ChaName.Text, datepicker.SelectedDate.ToString());
            Client.GetSystemMarkCountsAsync(Session.LoginUser.LoginName, ChaName.Text, datepicker.SelectedDate.ToString());
        }
    }
}
